package com.haust.su.ghyy.hospital.controller;

import com.haust.su.ghyy.common.result.Result;
import com.haust.su.ghyy.hospital.service.HospitalService;
import com.haust.su.ghyy.model.hosp.Hospital;
import com.haust.su.ghyy.vo.hosp.HospitalQueryVo;
import com.haust.su.ghyy.vo.hosp.HospitalSetQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author haustsusu
 * @create 2023-04-27-16:48
 */
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;

    //医院列表,条件查询带分页
    @GetMapping("list/{page}/{limit}")
    public Result listHospital(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            HospitalQueryVo hospitalQuery){

        Page<Hospital> pageModel=hospitalService.selectHospPage(page,limit,hospitalQuery);
        List<Hospital> content = pageModel.getContent();
        long elements = pageModel.getTotalElements();

        /*
        /测试
         */
        //Iterator<Hospital> iterator = content.iterator();
        //while (iterator.hasNext()){
        //    System.out.println(iterator.next());
        //}


        return Result.ok(pageModel);
    }


    //更新医院的上线状态
    @ApiOperation(value = "更新医院的上线状态")
    @GetMapping("updateHospStatus/{id}/{status}")
    public Result updateHospStatus(@PathVariable String id,@PathVariable Integer status){
        hospitalService.updateStatus(id,status);
        return Result.ok();
    }


    //医院详情信息
    @ApiOperation(value = "医院的详情信息")
    @GetMapping("showHospitalDetail/{id}")
    public Result showHospitalDetail(@PathVariable String id){
        Map<String,Object> map =hospitalService.getHospById(id);
        return Result.ok(map);
    }

}
